package handler

import (
	"context"
	"github.com/liuxd6825/dapr-go-ddd-sdk/utils/randomutils"
	"{{.Namespace}}/pkg/cmd-service/domain/{{.aggregate_name}}/event"
	"{{.Namespace}}/pkg/cmd-service/domain/{{.aggregate_name}}/field"
	"{{.Namespace}}/pkg/query-service/infrastructure/test"
	"testing"
)

func Test{{.Name}}QueryHandler(t *testing.T) {
	test.InitQuery()

	queryHandler := New{{.Name}}QueryHandler()
	ctx := context.Background()

    id := randomutils.UUID()
    tenantId := test.TenantId
    {{- range $i, $event := .Events}}

	t.Run("{{$event.EventSourcingHandler}}", func(t *testing.T) {
		e := event.New{{.Name}}(randomutils.UUID())
		e.Data = field.{{$event.DataFields.Name}}{
        {{- range $name, $property := $event.DataFields.Properties}}
            {{- if $property.NameIsId }}
            Id: id,
            {{- else if $property.IsItems }}
                {{- range $v, $itemCode := $property.GoAppTestItemsValue }}
                {{ $itemCode }}
                {{- end }}
            {{- else }}
            {{$name}} : {{$property.GoAppTestValue}},
            {{- end }}
        {{- end }}
		}
		if err := queryHandler.{{$event.EventSourcingHandler}}(ctx, e); err != nil {
			t.Error(err)
		}
	})
	{{- end }}
}
